```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Tomcat自定义错误页面配置指南 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        h1, h2, h3, h4 {
            font-family: 'Noto Serif SC', serif;
            font-weight: 600;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background-color: #2d3748;
            color: #f7fafc;
            border-radius: 0.5rem;
            overflow-x: auto;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .highlight {
            position: relative;
        }
        .highlight:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(118, 75, 162, 0.2);
            z-index: -1;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 md:py-32 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <div class="inline-block px-4 py-2 mb-6 bg-white bg-opacity-20 rounded-full">
                <span class="text-sm font-medium uppercase tracking-wider">Tomcat 最佳实践</span>
            </div>
            <h1 class="text-4xl md:text-6xl font-bold mb-6">Tomcat自定义错误页面配置指南</h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto">优雅处理错误，提升用户体验与系统可维护性的完整解决方案</p>
            <div class="mt-12 flex justify-center space-x-4">
                <a href="#configuration" class="px-6 py-3 bg-white text-indigo-800 font-medium rounded-lg hover:bg-opacity-90 transition duration-300">
                    <i class="fas fa-cog mr-2"></i>配置指南
                </a>
                <a href="#implementation" class="px-6 py-3 bg-transparent border-2 border-white text-white font-medium rounded-lg hover:bg-white hover:bg-opacity-10 transition duration-300">
                    <i class="fas fa-code mr-2"></i>代码实现
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 md:px-0 py-16">
        <article class="prose prose-lg max-w-none">
            <!-- Introduction -->
            <section class="mb-16">
                <p class="text-xl text-gray-700 leading-relaxed">
                    在Tomcat中配置自定义的错误页面和错误处理机制是提高用户体验和应用可维护性的关键步骤。通过自定义错误页面，你可以提供更友好的错误信息，并避免用户看到默认的服务器错误页面。本文将全面介绍从基础配置到高级实现的完整解决方案。
                </p>
            </section>

            <!-- Configuration Section -->
            <section id="configuration" class="mb-20">
                <h2 class="text-3xl font-bold mb-8 highlight">1. 配置自定义错误页面</h2>
                
                <div class="grid md:grid-cols-2 gap-8 mb-12">
                    <div class="card-hover bg-white p-6 rounded-xl shadow-md">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600 mr-4">
                                <i class="fas fa-file-code text-lg"></i>
                            </div>
                            <h3 class="text-xl font-semibold">1.1 修改web.xml文件</h3>
                        </div>
                        <p class="text-gray-700 mb-4">Tomcat使用web.xml文件来定义Web应用的配置，包括错误页面的设置。要配置自定义错误页面，可以在web.xml中添加&lt;error-page&gt;元素。</p>
                        <div class="code-block p-4 text-sm">
                            <pre>&lt;web-app ...&gt;
    &lt;!-- 自定义404错误页面 --&gt;
    &lt;error-page&gt;
        &lt;error-code&gt;404&lt;/error-code&gt;
        &lt;location&gt;/errors/404.html&lt;/location&gt;
    &lt;/error-page&gt;

    &lt;!-- 自定义500错误页面 --&gt;
    &lt;error-page&gt;
        &lt;error-code&gt;500&lt;/error-code&gt;
        &lt;location&gt;/errors/500.html&lt;/location&gt;
    &lt;/error-page&gt;

    &lt;!-- 自定义特定异常的错误页面 --&gt;
    &lt;error-page&gt;
        &lt;exception-type&gt;java.lang.NullPointerException&lt;/exception-type&gt;
        &lt;location&gt;/errors/null-pointer.html&lt;/location&gt;
    &lt;/error-page&gt;
&lt;/web-app&gt;</pre>
                        </div>
                        <div class="mt-4 text-sm text-gray-600">
                            <p><span class="font-medium">+ &lt;error-page&gt;:</span> 定义一个错误页面</p>
                            <p><span class="font-medium">+ &lt;error-code&gt;:</span> 指定错误代码（如404、500）</p>
                            <p><span class="font-medium">+ &lt;exception-type&gt;:</span> 指定特定的异常类型，用于自定义异常处理</p>
                            <p><span class="font-medium">+ &lt;location&gt;:</span> 指定错误页面的路径</p>
                        </div>
                    </div>
                    
                    <div class="card-hover bg-white p-6 rounded-xl shadow-md">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-purple-100 flex items-center justify-center text-purple-600 mr-4">
                                <i class="fas fa-server text-lg"></i>
                            </div>
                            <h3 class="text-xl font-semibold">1.2 配置Tomcat的context.xml</h3>
                        </div>
                        <p class="text-gray-700 mb-4">在Tomcat的conf/context.xml文件中，你也可以配置全局错误页面。需要注意的是，context.xml的错误页面设置会覆盖web.xml的设置。</p>
                        <div class="code-block p-4 text-sm">
                            <pre>&lt;Context ...&gt;
    &lt;ErrorPage errorCode="404" location="/errors/404.html"/&gt;
    &lt;ErrorPage errorCode="500" location="/errors/500.html"/&gt;
&lt;/Context&gt;</pre>
                        </div>
                        <div class="mt-4 p-4 bg-blue-50 rounded-lg">
                            <h4 class="font-medium text-blue-800 flex items-center mb-2">
                                <i class="fas fa-lightbulb mr-2"></i>专业提示
                            </h4>
                            <p class="text-blue-700 text-sm">全局配置适用于所有Web应用，而web.xml中的配置只对当前应用有效。根据你的需求选择合适的配置方式。</p>
                        </div>
                    </div>
                </div>
            </section>

            <!-- Implementation Section -->
            <section id="implementation" class="mb-20">
                <h2 class="text-3xl font-bold mb-8 highlight">2. 实现自定义错误处理</h2>
                
                <div class="grid md:grid-cols-2 gap-8 mb-12">
                    <div class="card-hover bg-white p-6 rounded-xl shadow-md">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-green-100 flex items-center justify-center text-green-600 mr-4">
                                <i class="fas fa-filter text-lg"></i>
                            </div>
                            <h3 class="text-xl font-semibold">2.1 使用Servlet过滤器</h3>
                        </div>
                        <p class="text-gray-700 mb-4">可以通过实现Filter接口来创建一个自定义的错误处理过滤器，以便在处理错误时执行特定的逻辑。</p>
                        <div class="code-block p-4 text-sm">
                            <pre>import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class CustomErrorFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        // 初始化代码
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        try {
            chain.doFilter(request, response);
        } catch (Exception e) {
            // 处理错误并转发到自定义错误页面
            HttpServletRequest req = (HttpServletRequest) request;
            HttpServletResponse res = (HttpServletResponse) response;
            req.setAttribute("error", e.getMessage());
            req.getRequestDispatcher("/errors/custom-error.html").forward(req, res);
        }
    }

    @Override
    public void destroy() {
        // 清理代码
    }
}</pre>
                        </div>
                    </div>
                    
                    <div class="card-hover bg-white p-6 rounded-xl shadow-md">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 rounded-full bg-yellow-100 flex items-center justify-center text-yellow-600 mr-4">
                                <i class="fas fa-leaf text-lg"></i>
                            </div>
                            <h3 class="text-xl font-semibold">2.2 使用Spring框架的@ControllerAdvice</h3>
                        </div>
                        <p class="text-gray-700 mb-4">如果你的应用使用Spring框架，可以使用@ControllerAdvice和@ExceptionHandler来处理异常并返回自定义的错误页面。</p>
                        <div class="code-block p-4 text-sm">
                            <pre>import org.springframework.http.HttpStatus;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String handleException(Exception ex, Model model) {
        model.addAttribute("error", ex.getMessage());
        return "error/500"; // 返回自定义错误页面视图
    }
}</pre>
                        </div>
                        <div class="mt-4 p-4 bg-blue-50 rounded-lg">
                            <h4 class="font-medium text-blue-800 flex items-center mb-2">
                                <i class="fas fa-info-circle mr-2"></i>扩展知识
                            </h4>
                            <p class="text-blue-700 text-sm">@ControllerAdvice是Spring MVC中处理全局异常的推荐方式，可以针对不同类型的异常定义不同的处理方法。</p>
                        </div>
                    </div>
                </div>
            </section>

            <!-- Best Practices Section -->
            <section class="mb-20">
                <h2 class="text-3xl font-bold mb-8 highlight">3. 配置错误页面的注意事项</h2>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="bg-white p-6 rounded-xl shadow-sm border-l-4 border-indigo-500">
                        <h3 class="text-xl font-semibold mb-3 flex items-center">
                            <i class="fas fa-map-signs text-indigo-500 mr-2"></i>3.1 确保路径正确
                        </h3>
                        <p class="text-gray-700">自定义错误页面的路径必须正确且文件必须存在。通常将错误页面放在WEB-INF下或其他受保护的目录，以防止被直接访问。</p>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm border-l-4 border-purple-500">
                        <h3 class="text-xl font-semibold mb-3 flex items-center">
                            <i class="fas fa-sync-alt text-purple-500 mr-2"></i>3.2 静态和动态错误页面
                        </h3>
                        <p class="text-gray-700">
                            <span class="font-medium">静态错误页面:</span> 简单的HTML文件，不涉及动态内容。<br>
                            <span class="font-medium">动态错误页面:</span> 可以使用JSP、Thymeleaf等模板引擎来展示动态内容。
                        </p>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm border-l-4 border-blue-500">
                        <h3 class="text-xl font-semibold mb-3 flex items-center">
                            <i class="fas fa-bug text-blue-500 mr-2"></i>3.3 异常处理和日志记录
                        </h3>
                        <p class="text-gray-700">确保在自定义错误页面中记录足够的错误信息，以帮助调试问题。可以在服务器日志中记录详细的错误信息。</p>
                    </div>
                    
                    <div class="bg-white p-6 rounded-xl shadow-sm border-l-4 border-green-500">
                        <h3 class="text-xl font-semibold mb-3 flex items-center">
                            <i class="fas fa-globe text-green-500 mr-2"></i>3.4 国际化
                        </h3>
                        <p class="text-gray-700">如果你的应用支持多语言，确保错误页面支持国际化，根据用户的语言选择不同的错误页面。</p>
                    </div>
                </div>
            </section>

            <!-- Visualization -->
            <section class="mb-20">
                <h2 class="text-3xl font-bold mb-8 highlight">Tomcat错误处理架构图示</h2>
                <div class="bg-white p-6 rounded-xl shadow-md">
                    <div class="mermaid">
                        graph TD
                            A[客户端请求] --> B{请求处理}
                            B -->|成功| C[返回正常响应]
                            B -->|失败| D[错误处理机制]
                            D --> E[web.xml配置]
                            D --> F[context.xml配置]
                            D --> G[Servlet过滤器]
                            D --> H[Spring @ControllerAdvice]
                            E --> I[自定义错误页面]
                            F --> I
                            G --> I
                            H --> I
                            I --> J[用户友好的错误页面]
                    </div>
                </div>
            </section>
        </article>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto max-w-5xl px-4 md:px-0">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-semibold text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">专注分享Java Web开发技术</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition duration-300 flex items-center">
                        <i class="fas fa-globe mr-2"></i> http://www.yuque.com/jtostring
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```